package day01;

import java.util.Stack;

/**
 * @author Jetwang
 * @version 1.0
 * @since 2023/3/12 12:22
 * 力扣 232. 用栈实现队列
 */
public class StackPractice03 {
    Stack<Integer> stack01 = new Stack<>();
    Stack<Integer> stack02 = new Stack<>();

    public StackPractice03() {

    }

    public void push(int x) {
        stack01.push(x);
    }

    public int pop() {
        if (stack02.isEmpty()) {
            if (stack01.isEmpty()) {
                return -1;
            }
            while (!stack01.isEmpty()) {
                stack02.push(stack01.pop());
            }
        }
        return stack02.pop();
    }

    public int peek() {
        if (stack02.isEmpty()) {
            if (stack01.isEmpty()) {
                return -1;
            }
            while (!stack01.isEmpty()) {
                stack02.push(stack01.pop());
            }
        }
        return stack02.peek();
    }

    public boolean empty() {
        return stack01.isEmpty() && stack02.isEmpty();
    }
}
